package com.kgar.repository;


import com.kgar.entity.graph.relationship.RelevantToRelation;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface RelevantToRepository extends Neo4jRepository<RelevantToRelation, Long> {
    @Transactional
    @Query("MATCH (jp:JobPosition {jobPositionId: $jobId}), (r:Resume {resumeId: $resumeId}) "
            + "MERGE (jp)-[rel:RELEVANT_TO]->(r) "
            + "ON CREATE SET rel.relevanceScore = $newRelevanceScore "
            + "ON MATCH SET rel.relevanceScore = rel.relevanceScore + $newRelevanceScore "
            + "RETURN rel.relevanceScore as relevanceScore")
    RelevantToRelation updateOrCreateRelevantToRelation(@Param("jobId") Long jobId,
                                                        @Param("resumeId") Integer resumeId,
                                                        @Param("newRelevanceScore") Double newRelevanceScore);

}


